package com.bipbip.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bipbip.modelo.Usuario;
import com.bipbip.modelo.Vehiculo;
import com.bipbip.repositorio.VehiculoDAO;

@Service
public class VehiculoServiceImpl implements VehiculoService {

	@Autowired
	private VehiculoDAO vehiculoDao;

	public List<Vehiculo> obtenerVehiculos(Usuario user) {
		return vehiculoDao.selectBy("idUsuario", user.getId());
	}

	public void guardar(Vehiculo vehiculo) {
		if (vehiculo.getId() == null) {
			vehiculoDao.insert(vehiculo);
		} else {
			vehiculoDao.update(vehiculo);
		}
	}

	public Vehiculo getVehiculo(Integer id) {
		return vehiculoDao.select(id);
	}

	public void borrar(Vehiculo vehiculo) {
		vehiculoDao.delete(vehiculo);
	}

	public void borrar(Integer id) {
		vehiculoDao.delete(id);
	}

}
